package com.example.dllo.my36kr.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.model.EventBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 *发现页的 近期活动页面
 * Created by CPC_272 on 16/8/27.
 */
public class EventAdapter extends BaseAdapter {
     private Context context;
    private List<EventBean.DataBean.DataBean2>eventBeen;

    public EventAdapter(Context context) {
        this.context = context;
    }

    public void setEventBeen(List<EventBean.DataBean.DataBean2> eventBeen) {
        this.eventBeen = eventBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return eventBeen!=null ?eventBeen.size():0;
    }

    @Override
    public Object getItem(int position) {
        return eventBeen!=null? eventBeen.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_event,parent ,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
             holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_title_event.setText(eventBeen.get(position).getActivityName());
        holder.tv_present_event.setText(eventBeen.get(position).getActivityDesc());
        holder.tv_city.setText(eventBeen.get(position).getActivityCity());
        holder.tv_stastus.setText(eventBeen.get(position).getActivityStatus());
        holder.tv_time.setText(eventBeen.get(position).getActivityTime());
        Picasso.with(context).load(eventBeen.get(position).getActivityImg()).error(R.mipmap.common_loading).placeholder(R.mipmap.common_avatar).into(holder.img_event);

        return convertView;
    }
    class ViewHolder {
        private TextView tv_title_event, tv_present_event, tv_city, tv_stastus, tv_time;
        private ImageView img_event;

        public ViewHolder(View view) {
            tv_city = (TextView) view.findViewById(R.id.city_event);//北京
            tv_title_event = (TextView) view.findViewById(R.id.tv_event_title);//标题
            tv_present_event = (TextView) view.findViewById(R.id.tv_event_present);//下面小字
            tv_stastus = (TextView) view.findViewById(R.id.stastus_event);//报名中
            tv_time = (TextView) view.findViewById(R.id.time_event);//时间
            img_event = (ImageView) view.findViewById(R.id.image_event);//定位符号

        }
    }
}
